import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:stop/pages/home/widget/home_like.dart';
import 'package:stop/pages/home/widget/home_nav.dart';
import 'package:stop/pages/home/widget/home_search.dart';
import 'package:stop/pages/home/widget/home_swipe.dart';

class HomePage extends StatefulWidget {
  const HomePage({ Key? key }) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  void initState() {
    // TODO: implement initState
    getResData();
    super.initState();
  }
  List swipeList = [];//轮播图
  List navList =[];
  List adList =[];
  List goodList=[];
  // 获取接口数据
  void getResData() async{
      Dio dio = Dio();
      Response res = await dio.get("http://smart-shop.itheima.net/index.php?s=/api/page/detail");
      List items = res.data['data']['pageData']['items'];
      setState(() {
        swipeList = items[1]['data'];
        navList = items[3]['data'];
        adList = items[4]['data'];
        goodList = items[6]['data'];
        print(goodList.toString());
        // 2.4 广告图片数据
        
      });
  }


  @override
  Widget build(BuildContext context) {
      return Scaffold(
      appBar: AppBar(
        title: Text("智慧商城",
        style: TextStyle(color:Colors.white),
        ),
        backgroundColor: Colors.red,
        centerTitle: true,
      ),
      body: ListView(
        children: [
          HomeSearch(),
          HomeSwipe(swipeList:swipeList),
          HomeNav(navList:navList),
          Image.network('${adList[0]['imgUrl']}'),
           Padding(
            padding: const EdgeInsets.only(top: 5, bottom: 5),
            child: Container(
              alignment: Alignment.center,
              child: const Text('—— 猜你喜欢 ——'),
            ),
           ),
           HomeLike(goodList:goodList)
        ],
      ),
    );
  }
}